//
//  WebViewController.m
//  Haen
//
//  Created by zengyuan on 16/6/15.
//  Copyright © 2016年 ;. All rights reserved.
//

#import "WebViewController.h"
//#import "BrokenNetworkView.h"

@interface WebViewController ()<WKNavigationDelegate>
//@property(nonatomic, strong) BrokenNetworkView *netView;
@end

@implementation WebViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    [self setNavButton];
    
//
//    if (self.webVIewConfiguration) {
//        self.webVIew = [[WKWebView alloc]initWithFrame:CGRectZero configuration:self.webVIewConfiguration];
////    }else{
        self.webVIew = [[UIWebView alloc]initWithFrame:self.view.bounds];
//    }

//    self.webVIew.navigationDelegate = self;
    [self.view addSubview:self.webVIew];
    
//    UIView *superView = self.view;
//    [self.webVIew mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(superView);
//        make.right.equalTo(superView.mas_right);
//        make.top.equalTo(self.mas_topLayoutGuideBottom);
//        make.bottom.equalTo(self.mas_bottomLayoutGuideTop);
//    }];
//    
////    //网络不给力
//    if (!NETWORK_AVAILABLE){
////        [self showNetView];
//        MBALERT(HTTPERROR_CANNOTREACH);
//    }else{
    if (self.showHttpUrl) {
        [self loadRequest];

    }else{
        [self loadLocal];
        }
//    }
    


    
    self.title = @"文章详情";
//    self.atitle;

    //prevent loading too long time
//    [self performSelector:@selector(cancelProgress) withObject:nil afterDelay:10];
}

-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    
    self.webVIew.frame = self.view.bounds;
    
}

-(void)dealloc{
//    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(cancelProgress) object:nil];
}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
}

//-(void)cancelProgress{
//    progress_hide
//}
//
//-(void)removeNoNetwork{
//    if(self.netView){
//        [self.netView removeFromSuperview];
//        self.netView = nil;
//    }
//}

-(void)loadRequest{
    
    
    if (![self.urlStr hasPrefix:@"http"]) {
        self.urlStr = [NSString stringWithFormat:@"http://%@",self.urlStr];
    }
    
    NSURL *url = [NSURL URLWithString:self.urlStr];
    [self.webVIew loadRequest:[NSURLRequest requestWithURL:url]];
    
    NSLog(@"%@", url);

}

-(void)loadLocal{

    NSURL * url = [NSURL URLWithString:self.urlStr];

    NSURLRequest * request = [NSURLRequest requestWithURL:url];
    [self.webVIew loadRequest:request];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation{
//    progress_show
}

- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error{
//    progress_hide
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
//    [self removeNoNetwork];
//    progress_hide
    
}


- (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error{
//    progress_hide
}


- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView{
//    progress_hide
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
